package com.cxlin.cwanandroid.ui.me.viewmodel

import android.util.Log
import com.cxlin.base.BaseViewModel
import com.cxlin.base.mvi.UiEvent
import com.cxlin.base.mvi.UiIntent
import com.cxlin.base.mvi.UiState
import com.cxlin.cwanandroid.App
import com.cxlin.cwanandroid.event.LoginEvent
import kotlinx.coroutines.flow.update
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**
 *
 * @Author: chenxunlin
 * @Date: 2024/4/29 15:50
 */
class MeViewModel : BaseViewModel() {

    sealed class MeUiState : UiState {
        object Idel : MeUiState()
        data class User(val result: com.cxlin.cwanandroid.model.bean.User?) : MeUiState()
    }

    sealed class MeEvent : UiEvent {}
    sealed class MeUiIntent : UiIntent {

    }

    override fun handleIntent(intent: UiIntent) {
    }

    override fun createInitState(): UiState {
       return MeUiState.Idel
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true, priority = 1)
    fun onLogin(event: LoginEvent) {
        Log.e("MeViewModel", "onLogin")
        mUiStateFlow.update { MeUiState.User(App.CURRENT_USER) }
    }
}